package com.example.demo.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.example.demo.system.service.ISFileService;
import com.example.demo.system.entity.SFile;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 附件表; 前端控制器
 * </p>
 *
 * @author tao
 * @since 2025-02-24
 */
@RestController
@RequestMapping("/sFile")
    public class SFileController {

    @Autowired
    private ISFileService sFileService;

    /**
    * 获取相关列表
     * @param current
     * @param size
     * @return
    */
    @GetMapping("/getSFileList")
    public Result<?> getSFileList(@RequestParam(value = "current", required = false, defaultValue = "1")Integer current,
                                            @RequestParam(value = "size", required = false, defaultValue = "10")Integer size,
                                            SFile sFile){

        Page<SFile> page = new Page<>(current,size);
        QueryWrapper<SFile> queryWrapper=new QueryWrapper<>(sFile);
        queryWrapper.orderByDesc("id");
        return Result.ok(sFileService.page(page,queryWrapper));
    }

    /**
         * 根据ID查询信息
         */
    @GetMapping("/getSFileById")
    public Result<?> getSFileById(Integer id){
        return Result.ok(sFileService.getById(id));
    }

    /**
         * 修改
         */
    @PutMapping("/updateSFile")
    @Transactional
    public Result<?> updateSFile(@RequestBody SFile sFile){
        return Result.ok(sFileService.updateById(sFile));
    }

    /**
         * 新增
         */
    @PostMapping("/addSFile")
    public Result<?> addSFile(@RequestBody SFile sFile){
        return Result.ok(sFileService.save(sFile));
    }

    /**
         * 删除
         */
    @DeleteMapping("/deleteSFileById")
    @Transactional
    public Result<?> deleteSFile(Integer id){
        return Result.ok(sFileService.removeById(id));
    }


}

